/**
 * @author Tobias Boehm
 *
 * 29.04.2011
 */
package org.anddev.andengine.extension.tbsengine.map;

import java.io.IOException;
import java.util.Vector;

import android.content.Context;

/**
 * This class helps to resolve the absolute paths to files with a specific
 * suffix in the same folder. This task is very common to classes like
 * {@link AbsMapLoader} and {@link AbsMapOverviewLoader} and there may be even 
 * more in further development.
 * 
 * @author Tobias Boehm
 *
 */
public class FilePathsResolver implements TBSmapConstants {

	/**
	 * A vector of absolute file paths.
	 */
	protected final Vector<String> mFilePaths;
	
	/**
	 * The folder of all those files.
	 */
	protected final String mFolderPath;
			
	/**
	 * This is the default constructor. The path resolving happens inside this
	 * constructor.
	 *  
	 * @param pContext
	 * @param pFolderPath - The folder of the wanted files.
	 * @param pFilesSuffix - The suffix of the wanted files.
	 * 
	 * @throws IOException if there is a problem by reading the file list of the given folder path. 
	 */
	public FilePathsResolver(final Context pContext, final String pFolderPath, final String pFilesSuffix) throws IOException{
		
		this.mFolderPath = pFolderPath;
		
		// Load all filepaths of this folder
		final String[] filePaths = pContext.getAssets().list(pFolderPath);
	
		// Determine files
		this.mFilePaths = new Vector<String>();
		
		for(String currentPath : filePaths){
			
			if(currentPath.endsWith(pFilesSuffix)){
				
				this.mFilePaths.add(pFolderPath+"/"+currentPath);
			}	
		}		
	}
}
